<script>
layui.config({
	base: '#(ctx)/manage/_assets/libs/layui/extends/'
}).extend({
	formSelects:'formSelects-v4.min'
}).use(['jquery', 'form', 'element', 'formSelects'], function(){
	var $ = layui.jquery, form = layui.form, element = layui.element, formSelects = layui.formSelects;

	### 自定义验证规则
	form.verify({
		title : function(value, item) {
			if (value.length < 2 || value.length > 50) {
				return '标题必须2到50位字符';
			}
		},
	});

	### 图片预览监听
	$(".layui-form-item img").on("click", function(){
		Jfsa.reviewImage(this);
	});

	### 监听选择文件按扭
	$(".jfsa-select-image").on("click", function(){
		var elem = this;
		### 选择图片窗口
		Jfsa.selectFile(layer, {
			elem : "#" + this.id,
			type : 2,
			title : "选择图片",
			maxmin : false,
			area : [ '800px', '480px' ],
			closeBtn : 1,
			shadeClose : false,
			anim : 1,
			moveOut : false,
			resize : false,
			btn : [ '选择变色项', '取消' ],
			accept : "image",### 接受的文件类型
			multiple : false,### 是否多选
			updPath : '#(jfsa_upload_path)',### 上传路径，如果指定它，返回的res.folder将会是以它开头
			ctxPath : '#(ctx)',### 项目路径
		 	done : function(res){
				if(res.size > 0){
					var url = (res.folder == "" ? "/" : res.folder + "/") + res.files[0];
					var ipt = $(elem).attr("jfsa-input");
					if(ipt) $("#" + ipt).val(url);
					var img = $(elem).attr("jfsa-img");
					if(img) $("#" + img).attr("src", url);
				}
			},
			error : function(res){
			}
		});
	});

	### ckeditorConfig参数来自于导入的_import_ckeditor_js.html文件
	var pcEditor = CKEDITOR.replace( 'ID_doc_content', ckeditorConfig);
	pcEditor.on( 'change', function( evt ) {
		$("#ID_doc_content_input").html(evt.editor.getData());
	});

	### ckeditorConfig参数来自于导入的_import_ckeditor_js.html文件
	var h5Editor = CKEDITOR.replace( 'ID_doc_content_h5', ckeditorConfig);
	h5Editor.on( 'change', function( evt ) {
		$("#ID_doc_content_h5_input").html(evt.editor.getData());
	});

});

</script>